package com.ruoyi.wjq.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wjq.domain.UserNote;
import com.ruoyi.wjq.service.IUserNoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户笔记Controller
 * 
 * @author wjq
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/wjq/note")
public class UserNoteController extends BaseController
{
    @Autowired
    private IUserNoteService userNoteService;

    /**
     * 查询用户笔记列表
     */
    @PreAuthorize("@ss.hasPermi('wjq:note:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserNote userNote)
    {
        System.out.println(userNote);
        if (userNote.getSubjectName()!=null){
            System.out.println(12345);
        }
        startPage();
        List<UserNote> list = userNoteService.selectUserNoteList(userNote);
      /*  for(UserNote userNote2 : list){
            System.out.println(userNote2);
        }*/
        return getDataTable(list);
    }

    /**
     * 根据题目ID查询用户笔记列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('wjq:note:list')")
    @GetMapping("/listByQuestionId/{questionId}")
    public AjaxResult listByQuestionId(@PathVariable("questionId") Long questionId)
    {
        UserNote query = new UserNote();
        query.setQuestionId(questionId);
        List<UserNote> list = userNoteService.selectUserNoteList(query);
        return success(list);
    }

    /**
     * 导出用户笔记列表
     */
    @PreAuthorize("@ss.hasPermi('wjq:note:export')")
    @Log(title = "用户笔记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserNote userNote)
    {
        List<UserNote> list = userNoteService.selectUserNoteList(userNote);
        ExcelUtil<UserNote> util = new ExcelUtil<UserNote>(UserNote.class);
        util.exportExcel(response, list, "用户笔记数据");
    }

    /**
     * 获取用户笔记详细信息
     */
    @PreAuthorize("@ss.hasPermi('wjq:note:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userNoteService.selectUserNoteById(id));
    }

    /**
     * 新增用户笔记
     */
    @PreAuthorize("@ss.hasPermi('wjq:note:add')")
    @Log(title = "用户笔记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserNote userNote)
    {
        return toAjax(userNoteService.insertUserNote(userNote));
    }

    /**
     * 修改用户笔记
     */
    @PreAuthorize("@ss.hasPermi('wjq:note:edit')")
    @Log(title = "用户笔记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserNote userNote)
    {
        return toAjax(userNoteService.updateUserNote(userNote));
    }

    /**
     * 删除用户笔记
     */
    @PreAuthorize("@ss.hasPermi('wjq:note:remove')")
    @Log(title = "用户笔记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userNoteService.deleteUserNoteByIds(ids));
    }
}
